package com.jiawa.train.business.controller.admin;

import com.jiawa.train.business.req.StationQueryReq;
import com.jiawa.train.business.req.StationSaveReq;
import com.jiawa.train.business.service.StationService;
import com.jiawa.train.common.resp.PageResult;
import com.jiawa.train.common.resp.Result;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/station")
@Slf4j
public class StationAdminController {

    @Resource
    private StationService stationService;
    @PostMapping("/save")
    public Result save(@RequestBody @Valid StationSaveReq req) {
        stationService.save(req);
        return Result.success();
    }
    @GetMapping("/page")
    public Result<PageResult> queryStationList(StationQueryReq  req) {
       PageResult pageResult = stationService.queryStationList(req);
       return Result.success(pageResult);
    }
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Long id) {
        stationService.delete(id);
        return Result.success();
    }

    @GetMapping("/query-all")
    public Result queryAll() {
        List stationList = stationService.queryAll();
        return Result.success(stationList);
    }
}

